# Replication Script for 
# "Coordinating Nominations: How to Deal with 
# an Incumbent Surplus after Electoral Reform"
# published in Japanese Journal of Political Science
# author: Jochen Rehmert

# Script replicates:
# Table: 3

# directory
setwd("...")

# packages 
library(foreign);library(stargazer)

# data 
dat <- read.dta("JEDS_data.dta")
dat$FUKENX <- as.character(dat$FUKENX)

dat2 <- read.dta("dist_char.dta")
dat2$newarea <- 1-dat2$geo_subset
dat <- merge(dat, dat2, by = "FUKENX")

# R's party support
dat$support <- NA
dat$support[dat$A6 == "LDP"] <- "LDP"
dat$support[dat$A6 == "NFP"] <- "NFP"
dat$support[dat$A6 == "DPJ"] <- "DPJ"
dat$support[dat$A6 == "SDP"] <- "SDP"
dat$support[dat$A6 == "JCP"] <- "JCP"
dat$support[dat$A6 == "NPH"] <- "NPH"
dat$support[dat$A6 == "Another Party" | dat$A6 == "No Party"] <- "others/none"

# R's ideological position
dat$lr <- as.character(dat$A14)     
dat$lr[dat$lr == "Neither"] <- 5
dat$lr[dat$lr == "Progressive"] <- 0
dat$lr[dat$lr == "Conservative"] <- 10
dat$lr <- as.numeric(dat$lr)

# socio-demographics
dat$female <- ifelse(dat$F1 == "Female",1,0)
dat$age <- dat$F2AGE

### --- prepare data: R knows LDP candidate in district --- ###

dat$knowsLDP <- NA
dat$knowsLDP[dat$A1P1X == "LDP" & dat$A1C1S1 == "Know very well"] <- "Know very well"
dat$knowsLDP[dat$A1P1X == "LDP" & dat$A1C1S1 == "Know somewhat"] <- "Know somewhat"
dat$knowsLDP[dat$A1P1X == "LDP" & dat$A1C1S1 == "Know only his or her name"] <- "Know only his or her name"

dat$knowsLDP[dat$A1P2X == "LDP" & dat$A1C2S1 == "Know very well"] <- "Know very well"
dat$knowsLDP[dat$A1P2X == "LDP" & dat$A1C2S1 == "Know somewhat"] <- "Know somewhat"
dat$knowsLDP[dat$A1P2X == "LDP" & dat$A1C2S1 == "Know only his or her name"] <- "Know only his or her name"

dat$knowsLDP[dat$A1P3X == "LDP" & dat$A1C3S1 == "Know very well"] <- "Know very well"
dat$knowsLDP[dat$A1P3X == "LDP" & dat$A1C3S1 == "Know somewhat"] <- "Know somewhat"
dat$knowsLDP[dat$A1P3X == "LDP" & dat$A1C3S1 == "Know only his or her name"] <- "Know only his or her name"

dat$knowsLDP[dat$A1P4X == "LDP" & dat$A1C4S1 == "Know very well"] <- "Know very well"
dat$knowsLDP[dat$A1P4X == "LDP" & dat$A1C4S1 == "Know somewhat"] <- "Know somewhat"
dat$knowsLDP[dat$A1P4X == "LDP" & dat$A1C4S1 == "Know only his or her name"] <- "Know only his or her name"

dat$knowsLDP[dat$A1P5X == "LDP" & dat$A1C5S1 == "Know very well"] <- "Know very well"
dat$knowsLDP[dat$A1P5X == "LDP" & dat$A1C5S1 == "Know somewhat"] <- "Know somewhat"
dat$knowsLDP[dat$A1P5X == "LDP" & dat$A1C5S1 == "Know only his or her name"] <- "Know only his or her name"

dat$knowsLDP[dat$A1P6X == "LDP" & dat$A1C6S1 == "Know very well"] <- "Know very well"
dat$knowsLDP[dat$A1P6X == "LDP" & dat$A1C6S1 == "Know somewhat"] <- "Know somewhat"
dat$knowsLDP[dat$A1P6X == "LDP" & dat$A1C6S1 == "Know only his or her name"] <- "Know only his or her name"

dat$knowsLDP[dat$A1P7X == "LDP" & dat$A1C7S1 == "Know very well"] <- "Know very well"
dat$knowsLDP[dat$A1P7X == "LDP" & dat$A1C7S1 == "Know somewhat"] <- "Know somewhat"
dat$knowsLDP[dat$A1P7X == "LDP" & dat$A1C7S1 == "Know only his or her name"] <- "Know only his or her name"

dat$knowsLDP[dat$A1P8X == "LDP" & dat$A1C8S1 == "Know very well"] <- "Know very well"
dat$knowsLDP[dat$A1P8X == "LDP" & dat$A1C8S1 == "Know somewhat"] <- "Know somewhat"
dat$knowsLDP[dat$A1P8X == "LDP" & dat$A1C8S1 == "Know only his or her name"] <- "Know only his or her name"

dat$knowsLDP_bin <- ifelse(dat$knowsLDP %in% c("Know very well", "Know somewhat"), 1,0)

summary(mod.1 <- glm(knowsLDP_bin ~  age + female + lr + support + popdensity + newarea + newcand, data = dat, family = binomial(link="logit")))

### "Next, I would like to ask you about the candidates who are from this district.  
### Please tell me which one (ones) of the candidates fit with the following statements." 

### --- LDP candidate is from Locality --- ###
dat$LDP_local <- NA
dat$LDP_local <- ifelse(dat$A2S1LDP == "Mentioned", 1,0 ) 

summary(mod.2 <- glm(LDP_local ~ age + female + lr +  support + popdensity + newarea + newcand, data = dat, family = binomial(link="logit")))


### --- LDP candidate has reputation as good local politician --- ###

dat$LDP_locpol <- NA
dat$LDP_locpol <- ifelse(dat$A2S2LDP == "Mentioned", 1,0 ) 

summary(mod.3 <- glm(LDP_locpol ~ age + female + lr +  support + popdensity + newarea + newcand, data = dat, family = binomial(link="logit")))

### --- LDP candidate arranges trips for supporters --- ###
dat$LDP_trips <- NA
dat$LDP_trips <- ifelse(dat$A2S4LDP == "Mentioned", 1,0 ) 

summary(mod.4 <- glm(LDP_trips ~ age + female + lr +  support+  popdensity + newarea + newcand, data = dat, family = binomial(link="logit")))

### --- LDP candidate attends weddings/funerals --- ###
dat$LDP_wedd <- NA
dat$LDP_wedd <- ifelse(dat$A2S5LDP == "Mentioned", 1,0 ) 

summary(mod.5 <- glm(LDP_wedd ~ age + female + lr +  support + popdensity + newarea + newcand, data = dat, family = binomial(link="logit")))

### --- LDP candidate brings subsidies to localities --- ###
dat$LDP_subs <- NA
dat$LDP_subs <- ifelse(dat$A2S6LDP == "Mentioned", 1,0 ) 

summary(mod.6 <- glm(LDP_subs ~ age + female + lr +  support + popdensity + newarea + newcand, data = dat, family = binomial(link="logit")))

### --- LDP candidate gets policies enacted --- ###
dat$LDP_pol <- NA
dat$LDP_pol <- ifelse(dat$A2S8LDP == "Mentioned", 1,0 ) 

summary(mod.7 <- glm(LDP_pol ~ age + female + lr +  support + popdensity + newarea + newcand, data = dat, family = binomial(link="logit")))

### --- LDP candidate takes care of personal requests --- ###
dat$LDP_req <- NA
dat$LDP_req <- ifelse(dat$A2S15LDP == "Mentioned", 1,0 ) 

summary(mod.8 <- glm(LDP_req ~  age + female + lr +  support + popdensity + newarea + newcand, data = dat, family = binomial(link="logit")))

### --- LDP candidate is in touch with common people --- ###
dat$LDP_touch <- NA
dat$LDP_touch <- ifelse(dat$A2S13LDP == "Mentioned", 1,0 ) 

summary(mod.9 <- glm(LDP_touch ~  age + female + lr + support+  popdensity + newarea + newcand, data = dat, family = binomial(link="logit")))

### --- LDP candidate speaks for famers/small businesses --- ###
dat$LDP_farmer <- NA
dat$LDP_farmer <- ifelse(dat$A2S10LDP == "Mentioned", 1,0 ) 

summary(mod.10 <- glm(LDP_farmer ~  age + female + lr + support + popdensity + newarea + newcand, data = dat, family = binomial(link="logit")))

library(stargazer) 

stargazer(list(mod.1, mod.2, mod.3, mod.4, mod.5, mod.6, mod.7, mod.8, mod.9, mod.10),
          omit = "support")

